<?php
class articlecateTag
{
    public function cate($options)
    {
        $options['field'] = isset($options['field']) ? trim($options['field']) : '*';
        $options['cateid'] = isset($options['cateid']) ? intval($options['cateid']) : 0;
        $options['where'] = isset($options['where']) ? trim($options['where']) : '';
        $options['num'] = isset($options['num']) ? intval($options['num']) : 0;
        $options['order'] = isset($options['order']) ? trim($options['order']) : 'id asc';
        if ($options['field'] != '*' || $options['where'] || $options['order'] != 'ordid') {
            $article_cate_mod = M('ArticleCate');
            $map = array('status' => '1');
            $select = $article_cate_mod->field($options['field']);
            $options['cateid'] && ($map['pid'] = $options['cateid']);
            $options['where'] && ($map['_string'] = $options['where']);
            $select->where($map);
            $options['num'] && $select->limit($options['num']);
            $select->order($options['order']);
            $data = $select->select();
        } else {
            if (false === ($cate_list = F('artcate_list'))) {
                $cate_list = D('ArticleCate')->cate_cache();
            }
            if ($options['cateid'] == 0) {
                $cate_list = $cate_list['p'];
            } else {
                $cate_list = $cate_list['s'][$options['cateid']];
            }
            $options['num'] && ($cate_list = array_slice($cate_list, 0, $options['num']));
            $data = $cate_list;
        }
        return $data;
    }
}